package com.boot.start.config.result;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author 墨龙吟
 * @version 1.0.0
 * @ClassName ResultResponse.java
 * @Email 2354713722@qq.com
 * @Description 普通返回实体
 * @createTime 2020年05月18日 - 23:04
 */
@Data
@Accessors(chain = true)
public class ResultResponse<T> implements Serializable {

    private static final long serialVersionUID = -5057776224030022081L;

    /** 消息 */
    private String msg;

    /** 返回值 */
    private String code;

    /** 数据 */
    private T data;

    public ResultResponse() { }

    public ResultResponse(StatusCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    public ResultResponse(String msg, String code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public static ResultResponse ok = new ResultResponse();

    public static ResultResponse fail = new ResultResponse();

    public ResultResponse<T> build(StatusCode resultCode, T data) {
        this.msg = resultCode.getMsg();
        this.code = resultCode.getCode();
        this.data = data;
        return this;
    }

    public ResultResponse<T> build(StatusCode resultCode) {
        this.msg = resultCode.getMsg();
        this.code = resultCode.getCode();
        return this;
    }

    /**
     * ResultResponse
     * @param msg  消息
     * @return  ResultResponse
     */
    public ResultResponse<T> msg(String msg) {
        this.msg = msg;
        return this;
    }

    /**
     * ResultResponse
     * @param code  状态码
     * @return  ResultResponse
     */
    public ResultResponse<T> code(String code) {
        this.code = code;
        return this;
    }

    /**
     * ResultResponse
     * @param data  数据
     * @return  ResultResponse
     */
    public ResultResponse<T> data(T data) {
        this.data = data;
        return this;
    }


}
